<?php

namespace Common\Logic;
class TuijianLogic{
	//生成邀请码
	public function generateYaoqing($region){
		if(empty($region)){
			$region = $this->getFour();
			while (M('Member')->field('region')->where(['region'=>$region])->find()){
				$region = $this->getFour();
			}
			return $region;
		}else{
			$region =$region.$this->getFour();
			while (M('Member')->field('region')->where(['region'=>$region])->find()){
				$region = $this->getFour();
			}
			return $region;
		}
	}
	private function getFour(){
		for($i=0;$i<4;$i++) {
			$fontsize = 6;
		
			$data = 'abcdefghijkmnpqrstuvwxy3456789';
			$fontcontent = substr($data, rand(0, strlen($data)-1), 1);
			$captch_code .= $fontcontent;
		}
		return $captch_code;
	}
}